package com.dgut.crm.system.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dgut.crm.common.util.ExtAjaxResponse;
import com.dgut.crm.common.util.ExtPageable;
import com.dgut.crm.system.entity.dto.NumberQueryDTO;
import com.dgut.crm.system.service.INumberService;


@Controller
@RequestMapping("/number")
public class NumberContreller 
{
	@Autowired
	private INumberService numberService;
	
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(NumberQueryDTO dto) 
	{
		try {
			if(null!=dto) {
				numberService.saveOrUpdate(dto);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			e.printStackTrace();
			return new ExtAjaxResponse(false,"操作失败！");
		}
		
	}
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse delete(@RequestParam Long id) 
	{
		try {
			NumberQueryDTO dto=  numberService.findOne(id);
			if(null!=dto) {
				numberService.delete(dto);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}

	}
	@RequestMapping("/deleteNumbers")
	public @ResponseBody ExtAjaxResponse deletenumbers(@RequestParam() Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids); 
			if(null!=idLists) {
				numberService.deleteNumbers(idLists);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}

	}
	
	@RequestMapping("/findOne")
	public @ResponseBody NumberQueryDTO findOne(@RequestParam Long id) 
	{
		NumberQueryDTO dto =  numberService.findOne(id);
		
		return dto;
	}
	
	@RequestMapping("/findPage")
	public @ResponseBody Page <NumberQueryDTO>findPage(NumberQueryDTO numberQueryDTO,ExtPageable pageable) 
	{
		Page<NumberQueryDTO>page =  numberService.findAll(NumberQueryDTO.getSpecification(numberQueryDTO), pageable.getPageable());
		return page;
	}

	
}
